<?php
include("../db_connect.php");

$display = "";
$pid = mysql_real_escape_string(htmlentities(trim($_GET['pid'])));
$sql = mysql_query("SELECT * FROM tblswaping where id='".$pid."' ") or die(mysql_error());


	while($row = mysql_fetch_array($sql))
	{
		
	echo $categories = $row['categories'];
	echo $trans = $row['transmission'];
		if($categories == "Auto"){
		
		$display ='<tr>
		<td valign="top">title</td>
			<td valign="top">
			<input type="text" id="__editname" value="'.$row['name'].'"/>
			</td>
		</tr>
		<tr>
		<td valign="top">Description</td>
			<td valign="top">
				<textarea id="__editdescription">'. $row['description'] .'</textarea>
			</td>
		</tr>
		<tr>
		<td valign="top">condition</td>
		<td valign="top">
					 <select id="__condtion" >
						<option  value="'.$row['conditions'].'" >Select Condition</option>
						<option  value="BrandNew" >BrandNew</option>
						<option  value="2ndHand">2ndHand</option>
						</select>
			</td>
		</tr>
		<tr>
		<td valign="top">transmission</td>
		<td valign="top">
		
					<select id = "__transmission">
											<option  value="'.$trans.'" >Select Transmission</option>
											<option value="Manual">Manual</option>
											<option value="Automatic">Automatic</option>
					</select>
			 
			</td>
		</tr>
		<tr>
		<td valign="top">fuel</td>
		<td valign="top">
		
		<select id="__fuel">
											<option  value="'.$row['fuel'].'" >Select Fuel</option>
											<option value="Gasoline">Gasoline</option>
											<option value="Diesel">Diesel</option>
											<option value="Lpg">LPG</option>
											<option value="Hybrid">Hybrid</option>
											<option value="Electric">Electric</option>
										</select>
										
										
			  
			</td>
		</tr>
		<tr>
		<td valign="top">Price</td>
		<td valign="top">
			  <input type="text" id="__price" value="'.$row['price'].'"/>
			</td>
		</tr>
		<tr>
		<td valign="top">quantity</td>
		<td valign="top">
			  <input type="text" id="__quantity" value="'.$row['quantity'].'"/>
			</td>
		</tr>
		<tr>
		<td>Types</td>
			<td valign="top">
			  
			  <select id = "__type">
			  
				$opt2 = <option id="__type" name="none" value="'.$row["types"].'">Select Types</option>;
				<option value="Cars">Cars</option>
				<option value="Motorcycle">MotorCycle</option>
				<option value="SUV/Pickups">SUV/Pickups</option>
				<option value="Vans">Vans</option>
				<option value="Others">Others</option>							
				
			</select>
			</td>
		</tr>
		<tr>
			<td valign="top">categories</td>
			<td valign="top">
			  <input type="text" id="__category" value="'.$categories.'">	
			</td>
		</tr>
		<tr>
			<td/>
			<td valign="top">
			   <button id="saveData">Save</button>
				<button id="Cancel">Cancel</button>
			</td>
		</tr>';
			
		
		}else{
			
$display = '<tr>
			<td valign="top">title</td>
			<td valign="top">
			<input type="text" id="__editname" value="'.$row['name'].'"/>
			</td>
		</tr>
		<tr>
			<td valign="top">Description</td>
			<td valign="top">
				<textarea id="__editdescription">'. $row['description'] .'</textarea>
			</td>
		</tr>
		
		<tr>
			<td valign="top">Price</td>
			<td valign="top">
			  <input type="text" id="__price" value="'.$row['price'].'"/>
			</td>
		</tr>
		<tr>
			<td valign="top">quantity</td>
			<td valign="top">
			  <input type="text" id="__quantity" value="'.$row['quantity'].'"/>
			</td>
		</tr>
		<tr>
		
			<td>Types</td>
			<td valign="top">
			
			  <select id = "__type">
			  
				$opt2 = <option id="__type" name="none" value="'.$row["types"].'">Select Types</option>;
				<option value="Cars">Cars</option>
				<option value="Motorcycle">MotorCycle</option>
				<option value="SUV/Pickups">SUV/Pickups</option>
				<option value="Vans">Vans</option>
				<option value="Others">Others</option>							
				
			</select>
			</td>
		</tr>
		<tr>
			<td valign="top">categories</td>
			<td valign="top">
			  <input type="text" disabled = "disabled" id="__category" value="'.$categories.'">	
			</td>
		</tr>
		<tr>
			<td/>
			<td valign="top">
			   <button id="SaveD">Save</button>
				<button id="Cancel">Cancel</button>
			</td>
		</tr>';
			 
			
	
	
	}
	}
?>

<script>
$(document).ready(function() {
$("#saveData").click(function() {
	
	var name = $("#__editname");
	var description = $("#__editdescription");
	var condition = $("#__condtion");
	var fuel = $("#__fuel");
	var transmission = $("#__transmission");
	var ctype = $("#__type"); 
	var price = $("#__price");
	var quantity = $("#__quantity");
	var category = $("#__category");
	var types = "edit";
		
	
	$.ajax({
		url:"admin/editmsgboxData.php?pid="+<?php echo $pid; ?>+"&name="+name.val()+"&description="+description.val()+"&condition="+condition.val()+"&fuel="+fuel.val()+"&transmission="+transmission.val()+"&ctype="+ctype.val()+"&price="+price.val()+"&quantity="+quantity.val()+"&category="+category.val()+"&types="+types,
		success:function(data){
			//$( "#msgbox" ).html(data);
			//$( "#msgbox" ).dialog();
			alert("successfully updated");
			location.reload();
			
		}
	
	});
	
});


$("#SaveD").click(function() {
	
	var name = $("#__editname");
	var description = $("#__editdescription");
	
	var ctype = $("#__type"); 
	var price = $("#__price");
	var quantity = $("#__quantity");
	var category = $("#__category");
	var types = "edited";
		
	
	$.ajax({
		url:"admin/editmsgboxData.php?pid="+<?php echo $pid; ?>+"&name="+name.val()+"&description="+description.val()+"&ctype="+ctype.val()+"&price="+price.val()+"&quantity="+quantity.val()+"&category="+category.val()+"&types="+types,
		success:function(data){
			alert("successfully updated");
			location.reload();
		}
	
	});
	
});

$("#Cancel").click(function(){

location.reload();

});



});






</script>

<div id="msgbox"></div>
<div>
	<table style="color white">
		<?php echo $display;?>
		<font style="color white"></font>
	</table>
</div>